using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Ent.Web.WebControl;
using Ent.Web.Helper;
using Ent.Voice.Nomination;
using Ent.Voice.Show;
public partial class Controls_DashEntrySet : DashEntrySet
{
    public Controls_DashEntrySet()
    {
        this.PreRender += new EventHandler(Controls_DashEntrySet_PreRender);
    }

    void Controls_DashEntrySet_PreRender(object sender, EventArgs e)
    {
        if (Event != null)
        {
            lblEventTitle.Font.Bold = true;
            lblEntries.Font.Size = DetailsFontSize;
            lblVotes.Font.Size = DetailsFontSize;
            lblEventDetail.Font.Size = DetailsFontSize;
            lblEventDetail.Text = "";
            if (!ShowDetails)
            {
                lblEventTitle.Text = Common.GetImageTextLink("ShowEvent.aspx?id=" + Event.Id, "Images/dj/event.gif", StringHelper.RestrictMaxChar(Event.Name, NameMaxChar), 15);
            }
            lblEntries.Text = GetDetailsText("LBL_Entries", (Event.Count < 0 ? "0" : Event.Count.ToString()), false);
            lblVotes.Text = GetDetailsText("LBL_Votes", Event.Votes.ToString(), true);
            if (ShowDetails)
            {
                lblEventDetail.Text += GetDetailsText("LBL_Fee", Event.FeeAmount.ToString() + " " + Event.Currency, true);
                SetStatus(ResourceHelper.Get("LBL_Voting"),  null,"vote.gif", Event.Status, Event.StartDate, Event.EndDate);
                SetStatus(ResourceHelper.Get("LBL_Nomination"), "Nominate.aspx", "nominate.gif", Event.NominationStatus, Event.NominationStartDate, Event.EndDate);
                SetStatus(ResourceHelper.Get("LBL_Sponsorship"), "Sponsor.aspx", "sponsor.gif", Event.SponsorStatus, Event.SponsorStartDate, Event.EndDate);
                lblEventDetail.Text += "<br />";
                
            }
            if (!ShowScroll)
            {
                tdEntries.Controls.Add(tabEntries);
                tabEntries.Height = Height;
                divEntries.Visible = false;
            }
            else
                divEntries.Style.Add(HtmlTextWriterStyle.Height, StringHelper.ConvertUnitToString(Height));
            tdDetails.Width = StringHelper.ConvertUnitToString(DetailsWidth);
            tabDetails.Width = StringHelper.ConvertUnitToString(DetailsWidth);
            tabEntries.Width = Width;
            PopulateEntry();
        }
    }
    public void SetStatus(string header, string link, string image, Ent.Voice.Show.EventStatus es, DateTime startDate, DateTime endDate)
    {
        if (es != EventStatus.Closed)
        {
            if (startDate.CompareTo(Event.MinDate) == 1)
            {
                lblEventDetail.Text += "<br /><br /><div class='header1' style='width: 100%; height: 20px;'>";
                lblEventDetail.Text += Common.GetImageTextLink((link == null ? null : link + "?id=" + Event.Id), "Images/dj/" + image, header, 14, new string[] { "c" });
                lblEventDetail.Text += "</div>";
                switch (es)
                {
                    case EventStatus.Started:
                        lblEventDetail.Text += GetDetailsText("LBL_StartedOn", "&nbsp;&nbsp;&nbsp;<font class='greensig'>" + startDate.ToShortDateString() + "</font>", false);
                        break;
                    case EventStatus.YetToStart:
                        lblEventDetail.Text += GetDetailsText("LBL_StartingOn", "&nbsp;&nbsp;&nbsp;<font class='orangesig'>" + startDate.ToShortDateString() + "</font>", false);
                        break;
                }
                if (endDate.CompareTo(Event.MaxDate) == 1)
                    lblEventDetail.Text += GetDetailsText("LBL_EndingOn", "<br />&nbsp;&nbsp;&nbsp;" + endDate.ToShortDateString(), true);
            }
        }
        else
        {
            lblEventDetail.Text += "<br /><br /><div class='header1' style='width: 100%; height: 20px;'>";
            lblEventDetail.Text += "<b><img src='Images/dj/" + image + "' style='width: 14px'>" + header + "</b>";
            lblEventDetail.Text += "</div>";
            lblEventDetail.Text += GetDetailsText("LBL_Status", "&nbsp;&nbsp;&nbsp<font class='redsig'>" + ResourceHelper.Get("LBL_Closed") + "</font>", false);
        }
    }
    private string GetDetailsText(string title, string value, bool newLine)
    {
        string retValue = "";
        if (newLine)
            retValue = "<br />";
        return retValue + "&nbsp;<b>" + ResourceHelper.Get(title) + "</b> " + value;
    }
    private void PopulateEntry()
    {
        int maxInColumn = MaxOnScreen / MaxInRow;
        int end = MaxOnScreen;
        if (Event.Entries == null)
            return;
        if (Event.Entries.Length < end)
            end = Event.Entries.Length;
        TableRow tr = new TableRow();
        if (end <= 0) return;
        for (int i = 0; i < end; i++)
        {
            Entry entry = (Entry)Event.Entries.GetValue(i);

            if (entry.Id != -1)
            {
                TableCell tc = GetCell();
                tc.Height = Unit.Percentage(100);
                //tc.CssClass = "generaltd";
                tc.Width = this.EntryTemplate.Width == Unit.Percentage(100)
                    ? Unit.Percentage(100 / MaxInRow)
                    : this.EntryTemplate.Width;
                DashEntry de = (DashEntry)CreateDashEntry(entry);
                tc.Controls.Add((System.Web.UI.Control)de);
                tr.Cells.Add(tc);
            }
            int rem = 0;
            Math.DivRem(i, MaxInRow, out rem);
            if (rem == (MaxInRow - 1) || i == Event.Entries.Length - 1)
            {
                tabEntries.Rows.Add(tr);
                tr = new TableRow();
            }
        }
    }
    private iControls_DashEntry CreateDashEntry(Entry entry)
    {
        iControls_DashEntry de = (iControls_DashEntry)LoadControl("DashEntry.ascx");
        Common.SetDashEntry(ref de, this.EntryTemplate, MaxInRow);
        de.Entry = entry;
        return de;
    }
    private TableCell GetCell()
    {
        TableCell tc = new TableCell();
        tc.VerticalAlign = VerticalAlign.Top;
        tc.HorizontalAlign = HorizontalAlign.Left;
        return tc;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
    }
}
